package ACwing.P4Math.Combinatorial_Number;

import java.io.*;

/**
 * @Date : 2023-03-24
 * @Description: 886. 求组合数 II
 * C62=6x5/2x1
 * Cab=Ca-1 b +Ca-1 b-1
 * 10w  递推
 * a/b mod p  不等于(a mod p)/ ( b mod p)
 * 询问次数一般，数的范围大    预处理   O（nlogn)
 */
public class CN02 {
    static BufferedReader br= new BufferedReader(new InputStreamReader(System.in));
    static BufferedWriter bw= new BufferedWriter(new OutputStreamWriter(System.out));
    static int n;
    static int N=100010;
    static int mod= (int) (1e9+7);
    //预处理所有阶乘的情况
    static long[] fact=new long[N],infact=new long[N];
    public static void main(String[] args) throws IOException {
        fact[0]=infact[0]=1;
        for (int i = 1; i < N; i++) {
            //初始化所有阶乘情况 a!阶乘,fact[i]=i!%mod
            //infact[i]=(i!)^(-1)%mod
            fact[i]=fact[i-1]*i%mod;
            infact[i]=infact[i-1]*qmi(i,mod-2,mod)%mod;//逆元
        }
        n=Integer.parseInt(br.readLine());
        int a,b;
        while (n--!=0){
            String[] strings = br.readLine().split("\\s+");
            a=Integer.parseInt(strings[0]);
            b=Integer.parseInt(strings[1]);
            bw.write(String.valueOf (fact[a]*infact[b]%mod*infact[a-b]%mod));
            bw.newLine();
        }
        bw.flush();
    }
    static long qmi(long a,long k,long p){ //快速幂
        long res=1;
        while (k!=0){
            if((k&1)==1) res=res*a%p;
            a=a*a%p;
            k>>=1;
        }
        return  res;
    }
}
